//
//  EJSCommentOrderViewController.m
//  EnjoyShoppingStreet
//
//  Created by lifayu on 2018/1/10.
//  Copyright © 2018年 lifayu. All rights reserved.
//

#import "EJSCommentOrderViewController.h"
#import "FlyRatingBarView.h"

#import "EJSCommentOrderRequest.h"

@interface EJSCommentOrderViewController ()
@property (weak, nonatomic) IBOutlet UILimitTextView *contentTextView;
@property (weak, nonatomic) IBOutlet FlyRatingBarView *ratingBarView;

@end

@implementation EJSCommentOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)configOwnViews{
    self.title = @"发表评价";
    
    self.contentTextView.placeHolder = @"说说它的优点或者不足的地方吧～";
    [self.ratingBarView setImageDeselected:@"star_1" halfSelected:@"star_2" fullSelected:@"star_2" andDelegate:nil];
    [self.ratingBarView displayRating:5];
}

- (IBAction)commentAction:(UIButton *)sender {
    NSString *comment = self.contentTextView.text;
    if (!comment || comment.length ==0){
        [[HUDHelper sharedInstance] tipMessage:@"请输入评论内容"];
        return;
    }
    NSString *rating = @((int)self.ratingBarView.rating).stringValue;
    
    EJSCommentOrderRequest *req = [EJSCommentOrderRequest new];
    req.star = rating;
    req.content = comment;
    req.orderId = self.orderId;
    [req asyncRequestWithsuccessHandler:^(BaseResponse *response) {
        [[HUDHelper sharedInstance] tipMessage:@"评价成功"];
        
        [self leftBarButtonAction:nil];
    } failHandler:^(BaseResponse *response) {
        [[HUDHelper sharedInstance] tipMessage:response.message];
    }];
    
}


@end
